/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package inet.controller;

import inet.dao.TimeKeepingDAO;
import inet.dao.TimeKeepingDetailDAO;
import inet.entity.TimeKeepingDetail;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author ÂuNgọcThái
 */
@ManagedBean
@SessionScoped
public class TKDController extends UserController{

    /**
     * Creates a new instance of TKDController
     */
    TimeKeepingDetailDAO tkdDAO = null;
    TimeKeepingDetail tkd = null;
    List<TimeKeepingDetail> lstTKD = null;
    TimeKeepingDAO tkDAO = null;

    public TKDController() {
        tkd = new TimeKeepingDetail();
        tkdDAO = new TimeKeepingDetailDAO();
        lstTKD = new ArrayList<TimeKeepingDetail>();
        tkDAO = new TimeKeepingDAO();
    }

    public TimeKeepingDAO getTkDAO() {
        return tkDAO;
    }

    public void setTkDAO(TimeKeepingDAO tkDAO) {
        this.tkDAO = tkDAO;
    }

    public TimeKeepingDetailDAO getTkdDAO() {
        return tkdDAO;
    }

    public void setTkdDAO(TimeKeepingDetailDAO tkdDAO) {
        this.tkdDAO = tkdDAO;
    }

    public TimeKeepingDetail getTkd() {
        return tkd;
    }

    public void setTkd(TimeKeepingDetail tkd) {
        this.tkd = tkd;
    }
    
    public List<TimeKeepingDetail> getLstTKD() {
        return lstTKD;
    }

    public void setLstTKD(List<TimeKeepingDetail> lstTKD) {
        this.lstTKD = lstTKD;
    }
    
    public BigDecimal getTkID(){
        tkDAO = new TimeKeepingDAO();
        return tkDAO.getID(empLogin.getEmp_id());
    }
    
    public List<TimeKeepingDetail> getLstTimeKeepingDetail() {
        tkdDAO = new TimeKeepingDetailDAO();
        lstTKD = tkdDAO.getAllTKD(getTkID());
        return lstTKD;
    }

    public int countDay() {
        tkdDAO = new TimeKeepingDetailDAO();
        int i = countDateOfMonth() - tkdDAO.countTKD(getTkID());
        return i;
    }

    public int countDateOfMonth() {
        int day = 31;
        SimpleDateFormat sd = new SimpleDateFormat("MM/yyyy");
        try {
            Date d = sd.parse(noteDate());
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            day = c.getActualMaximum(Calendar.DAY_OF_MONTH);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return day;
    }

    public String noteDate() {
        DateFormat dateFormat = new SimpleDateFormat("MM/yyyy");
        Date date = new Date();
        return dateFormat.format(date);
    }
    
    public List<TimeKeepingDetail> getLstAll() {
        tkdDAO = new TimeKeepingDetailDAO();
        lstTKD = tkdDAO.getAll();
        return lstTKD;
    }

}
